package com.tywj.buscustomerapp.view.item;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tywj.buscustomerapp.R;
import com.tywj.buscustomerapp.model.bean.MyTicketBean;
import com.tywj.buscustomerapp.model.bean.TravelBean;
import com.tywj.buscustomerapp.utils.TimeRender;
import com.tywj.buscustomerapp.utils.myadapter.item.AdapterItem;
import com.tywj.buscustomerapp.view.activity.EvaluateActivity;
import com.tywj.buscustomerapp.view.activity.MapTicketActivity;
import com.tywj.buscustomerapp.view.myview.ToastJoe;

import java.sql.Time;

public class MyTravelItem implements AdapterItem<TravelBean.DataBean.ResultListBean> {
    private TextView tiemView;
    private TextView stateView;
    private TextView travelView;
    private TextView startView;
    private TextView endView;
    private LinearLayout line;
    private TextView bus_time;
    private Context context;

    @Override
    public int getLayoutResId() {
        return R.layout.item_mytravel;
    }

    @Override
    public void bindViews(@NonNull View root) {
        tiemView = root.findViewById(R.id.time);
        stateView = root.findViewById(R.id.state);
        travelView = root.findViewById(R.id.travel_number);
        startView = root.findViewById(R.id.start);
        endView = root.findViewById(R.id.end);
        line = root.findViewById(R.id.line);
        context = root.getContext();
        bus_time = root.findViewById(R.id.bus_time);
    }

    @Override
    public void setViews() {

    }

    @Override
    public void handleData(final TravelBean.DataBean.ResultListBean myTicketBean, int position) {
        tiemView.setText(myTicketBean.getCcsj());
        bus_time.setText(myTicketBean.getScsj());
        startView.setText(myTicketBean.getGmqsz());
        endView.setText(myTicketBean.getGmzdz());
        stateView.setText(myTicketBean.getDdzt());
        travelView.setText(myTicketBean.getQsz()+"—"+myTicketBean.getZdz());
        if (myTicketBean.getDdzt().equals("待乘车")){
            stateView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.tag_ori));
            stateView.setTextColor(context.getResources().getColor(R.color.white));
        }else if (myTicketBean.getDdzt().equals("已乘车")){
            stateView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.tag_green));
            stateView.setTextColor(context.getResources().getColor(R.color.text_tab));
        }else if (myTicketBean.getDdzt().equals("已完成")){
            stateView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.tag_green));
            stateView.setTextColor(context.getResources().getColor(R.color.text_tab));
        }else{
            stateView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.tag_yellow));
            stateView.setTextColor(context.getResources().getColor(R.color.text));
        }
        if (myTicketBean.getTicketType()==1){
            stateView.setText("月票");
            stateView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.tag_yellow));
            stateView.setTextColor(context.getResources().getColor(R.color.text));
        }
        line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (myTicketBean.getDdzt().equals("待乘车") || myTicketBean.getDdzt().equals("已乘车")){
                    Intent intent = new Intent(v.getContext(), MapTicketActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("tic", myTicketBean);
                    intent.putExtras(bundle);
                    v.getContext().startActivity(intent);
                }else if (myTicketBean.getDdzt().equals("已完成")){
                    if (myTicketBean.getCcsj().substring(0,10).equals(TimeRender.getFullDateStr5())){
                        Intent intent = new Intent(v.getContext(), EvaluateActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("ticket", myTicketBean);
                        intent.putExtras(bundle);
                        v.getContext().startActivity(intent);
                    }else{
                        ToastJoe.getmToastJoe().ToastLongShow(v.getContext(),null,"只可评论当日班线");
                    }
                }
            }
        });
    }
}
